home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / ProcDoggie 1.0a6 / UProcessUtils.p < prev   
Encoding:
Text File  |  1991-02-07  |  10.2 KB  |  251 lines  |  [TEXT/MPS ]

  1. UNIT UProcessUtils;
  2.  
  3. {-------------------------------------------------------------------------------
  4. #
  5. #    Apple Macintosh Developer Technical Support
  6. #
  7. #    Interfaces for the guts of the ProcDoggie application
  8. #
  9. #    Program:    ProcDoggie
  10. #    File:        UProcessUtils.p - Pascal Implementation
  11. #
  12. #    by:        Forrest Tanaka
  13. #
  14. #    Copyright © 1988-1991 Apple Computer, Inc.
  15. #    All rights reserved.
  16. #
  17. --------------------------------------------------------------------------------
  18. #
  19. #    This unit is a high-level interface to the Process Manager.  It contains
  20. #    routines which allow you to launch a process, terminate a process, count the
  21. #    number of open processes, find a process given a file specification, and
  22. #    manage a list of documents for a process to open or print when it is
  23. #    launched.
  24. #
  25. #    The LaunchProcess routine is the most important routine in this unit.  It
  26. #    lets you launch either an application or a desk accessory and optionally lets
  27. #    you pass it a list of documents for the launched application to open or print
  28. #    (desk accessories don’t have document lists).
  29. #
  30. -------------------------------------------------------------------------------}
  31. {[j=20/57/1$] Pasmat Options}
  32.  
  33.  
  34. INTERFACE
  35.  
  36.  
  37. (*******************************************************************************
  38. * Used Units
  39. *******************************************************************************)
  40.  
  41.     USES
  42.         (* Group 1 *)
  43.          Types
  44.         ,QuickDraw
  45.  
  46.         (* Group 2 *)
  47.         ,AppleEvents
  48.         ,Errors
  49.         ,Events
  50.         ,OSUtils
  51.         ,Memory
  52.         ,Resources
  53.         ,SegLoad
  54.  
  55.         (* Group 3 *)
  56.         ,Aliases
  57.         ,Files
  58.         ,Processes
  59.         ;
  60.  
  61.  
  62. (*******************************************************************************
  63. * Types
  64. *******************************************************************************)
  65.  
  66.     TYPE
  67.         (* Flag to indicate whether document list is for printing or opening *)
  68.         LaunchModeCode = (kJustLaunch, kOpenLaunch, kPrintLaunch);
  69.  
  70.         (* Document list entry for opening apps with docs to open or print *)
  71.         DocListEntryPtr = ^DocListEntryRec;
  72.         DocListEntryHnd = ^DocListEntryPtr;
  73.         DocListEntryRec = RECORD
  74.             next:    DocListEntryHnd; {Link to the next document list record}
  75.             docFile: FSSpec           {File specification}
  76.         END;
  77.  
  78.         (* Document list for opening apps with docs to open or print *)
  79.         DocListRec = RECORD
  80.             docList:   DocListEntryHnd; {Handle to the first document list entry}
  81.             openPrint: LaunchModeCode   {Opening or printing documents?}
  82.         END;
  83.         DocListPtr = ^DocListRec;
  84.         DocListHnd = ^DocListPtr;
  85.  
  86.  
  87. (*******************************************************************************
  88. * CreateDocList - Create a new document list
  89. *
  90. * This routine creates a new document list and returns a handle to it.  If there
  91. * isn’t enough memory for a new document list, CreateDocList returns NIL.
  92. *
  93. * If openOrPrint is kOpenLaunch, then the list of documents that are put into
  94. * the new document list will be opened when the application is launched.  If
  95. * openOrPrint is kPrintLaunch, then the list of documents will be printed when
  96. * the application is launched.  If kJustLaunch or any other value is passed in
  97. * openOrPrint, then no document list is created.  CreateDocList returns NIL in
  98. * this case.  This isn’t really a conflict with returning NIL when there’s not
  99. * enough memory for the new document list because the calling routine can check
  100. * to see if openOrPrint is valid or not itself.
  101. *******************************************************************************)
  102.  
  103.     FUNCTION CreateDocList (openOrPrint: LaunchModeCode): DocListHnd;
  104.  
  105.  
  106. (*******************************************************************************
  107. * IsEmptyDocList - Return TRUE if the specified document list is empty.
  108. *
  109. * IsEmptyDocList returns TRUE if the document list specified by "theList" is
  110. * empty.  “Empty” can mean either that theList is NIL or theList is a handle to
  111. * a document list that contains no documents.  It returns FALSE if there’s at
  112. * least one entry in "theList".
  113. *
  114. * theList must either be a valid handle to a document list or it must be NIL.
  115. * IsEmptyDocList is unpredictable if this isn’t true.
  116. *******************************************************************************)
  117.  
  118.     FUNCTION IsEmptyDocList (theList: DocListHnd): Boolean;
  119.  
  120.  
  121. (*******************************************************************************
  122. * AddToDocList - Add a document file specification to a document list
  123. *
  124. * AddToDocList adds the file specified by "newFile" to the end of the document
  125. * list specified by "theList".  If there isn’t enough memory to add a new file
  126. * to the document list, then AddToDocList returns memFullErr.  Otherwise, noErr
  127. * is returned.
  128. *
  129. * theList MUST be a valid handle to an initialized document list.  I won’t be
  130. * responsible for AddToDocList’s actions if this isn’t true.
  131. *******************************************************************************)
  132.  
  133.     FUNCTION AddToDocList (newFile: FSSpec;
  134.                            theList: DocListHnd): OSErr;
  135.  
  136.  
  137. (*******************************************************************************
  138. * DisposeDocList - Dispose of a document list
  139. *
  140. * DisposeDocList deallocates all the memory occupied by the document list
  141. * specified by the "theList" parameter.  If theList is NIL, then nothing is
  142. * done.  If it’s not a valid DocListHnd, DisposeDocList is unpredictable.
  143. *******************************************************************************)
  144.  
  145.     PROCEDURE DisposeDocList (theList: DocListHnd);
  146.  
  147.  
  148. (*******************************************************************************
  149. * WereInFront - Test to see if this application is in front or not
  150. *
  151. * This routine determines whether this application is the front-most application
  152. * or not.  If it is, then TRUE is returned.  If it isn’t, then FALSE is
  153. * returned.
  154. *******************************************************************************)
  155.  
  156.     FUNCTION WereInFront: Boolean;
  157.  
  158.  
  159. (*******************************************************************************
  160. * FindProcess - Find a process with specified file and name
  161. *
  162. * FindProcess searches the Process Manager’s process list for a process that was
  163. * launched from the file specified by "testFile".  If the process being searched
  164. * is a DA, then the "daName" parameter must specify the name of the desk
  165. * accessory (i.e. the name of the DRVR resource, including the initial null
  166. * character).  If the process is found, then information about the process is
  167. * returned in the "testFileInfo" parameter, and FindProcess returns TRUE.  If
  168. * the process could not be found, then FALSE is returned, and "testFileInfo" is
  169. * unchanged.
  170. *
  171. * Warning: the processName and processAppSpec fields of "testFileInfo" are NOT
  172. * valid when FindProcess returns TRUE.  If the name and FSSpec of the found file
  173. * are desired, then the calling routine must allocate space for those fields
  174. * and call GetProcessInfo itself, passing the ProcessInfoRec returned by this
  175. * routine as a parameter.
  176. *******************************************************************************)
  177.  
  178.     FUNCTION FindProcess (testFile:         FSSpec;
  179.                           daName:           StringPtr;
  180.                           VAR testFileInfo: ProcessInfoRec): Boolean;
  181.  
  182.  
  183. (*******************************************************************************
  184. * LaunchProcess - Launch the specified process
  185. *
  186. * This routine launches the process whose file has the location and name
  187. * specified by "processFile" parameter.  The process’s resulting serial number
  188. * is returned in the returnPSN parameter.  If the process to be launched is a
  189. * desk accessory, then the name of the desk accessory (including the initial
  190. * null character that desk accessories require) is passed in daName.  IF NIL is
  191. * passed in daName, then the first desk accessory found in the specified file
  192. * (according to the Resource Manager) is launched.  If an application is being
  193. * launched, then daName is ignored.  The options parameter specifies options to
  194. * use when launching the new process.  It has the same values and meanings as
  195. * the LaunchFlags type defined in the Process Manager chapter of Inside
  196. * Macintosh VI.  If a desk accessory is being launched, then only the
  197. * launchContinue flag has significance.
  198. *
  199. * A list of documents to be opened or printed by the launched application can
  200. * optionally be specified by the docList parameter.  If no documents are
  201. * specified, then docList should be NIL.  See the document list routines defined
  202. * early in this unit.
  203. *
  204. * LaunchProcess determines whether to launch an application or desk accessory
  205. * based on the type code of the file specified by processFile.  If the file’s
  206. * type is APPL, then LaunchProcess attempts to launch it as an application.  If
  207. * the file has any other type, then LaunchProcess attempts to launch a desk
  208. * accessory in that file.
  209. *
  210. * LaunchProcess returns two kinds of errors.  One error is returned as a
  211. * function result.  These kinds of errors are generated by any call that occurs
  212. * during the execution of LaunchProcess that is only used to manage the
  213. * launching of the specified application rather than launching the application
  214. * itself.   The launchError parameter returns the error code of any error that
  215. * occurs when the application is actually launched.
  216. *******************************************************************************)
  217.  
  218.     FUNCTION LaunchProcess (processFile:     FSSpec;
  219.                             daName:          StringPtr;
  220.                             docList:         DocListHnd;
  221.                                     options:         LaunchFlags;
  222.                             VAR returnPSN:   ProcessSerialNumber;
  223.                                     VAR launchError: OSErr): OSErr;
  224.  
  225.  
  226. (*******************************************************************************
  227. * CountProcesses - Count the number of open processes
  228. *
  229. * This routine searches through the Process Manager’s process list and counts
  230. * the number of open processes.  The result is returned.
  231. *******************************************************************************)
  232.  
  233.     FUNCTION CountProcesses: Integer;
  234.  
  235.  
  236. (*******************************************************************************
  237. * TerminateProcess - Terminate a process
  238. *
  239. * This routine causes the process specified by "theProcessNum" to be terminated.
  240. * If an error occurs, then the error code is returned.
  241. *******************************************************************************)
  242.  
  243.     FUNCTION TerminateProcess (theProcessNum: ProcessSerialNumber): OSErr;
  244.  
  245.  
  246. IMPLEMENTATION
  247.  
  248.     {$I UProcessUtils.inc1.p}
  249.  
  250. END.
  251.